//
//  TaskMoreViewController.m
//  firstpoint
//
//  Created by 李雪虎 on 2017/7/18.
//  Copyright © 2017年 xzcysoft. All rights reserved.
//

#import "TaskMoreViewController.h"
#import "LeeHomepageTableViewCell.h"
@interface TaskMoreViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    int page;
}
@property(nonatomic,strong)UITableView *renwuTableView;
@property(nonatomic,strong)NSMutableArray *renwuArray;
@end

@implementation TaskMoreViewController
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden=NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    page=0;
    self.title = @"更多任务";
    self.view.backgroundColor = [UIColor whiteColor];
    _renwuArray = [NSMutableArray array];
    [self addShoppingMallTableView];//
    [self httpRquestRenWuUrl];
    // Do any additional setup after loading the view.
}
//添加表视图
-(void)addShoppingMallTableView{
    //表格
    _renwuTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, width_screen, height_screen-64-40) style:UITableViewStyleGrouped];
    _renwuTableView.backgroundColor = [UIColor clearColor];
    _renwuTableView.showsVerticalScrollIndicator = NO;//隐藏滑动条
    
    _renwuTableView.separatorColor = COLOR(229, 230, 231, 1);//分割线颜色
    _renwuTableView.delegate = self;
    _renwuTableView.dataSource = self;
    [_renwuTableView registerNib:[UINib nibWithNibName:@"LeeHomepageTableViewCell" bundle:nil] forCellReuseIdentifier:@"OenCell"];
    [self.view addSubview:_renwuTableView];
    //上拉加载
    MJRefreshAutoGifFooter*footer = [MJRefreshAutoGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
    [HTTPURL MJfoodDH:footer];
    _renwuTableView.mj_footer = footer;
    
}
-(void)loadData{
    page++;
    [self httpRquestRenWuUrl];
}
#pragma mark --tableView 代理方法
//区头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
//cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 100;
}

//多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _renwuArray.count;
}
//几个区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
//区尾高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 40;
}

//cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LeeHomepageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OenCell"];
    if (_renwuArray.count>1) {
        cell.titleLabel.text = [NSString stringWithFormat:@"%@金豆",_renwuArray[indexPath.row][@"title"]];
        cell.contenLabel.text =[NSString stringWithFormat:@"%@金豆",_renwuArray[indexPath.row][@"description"]];
        cell.jinDouLbale.text = [NSString stringWithFormat:@"%@金豆",_renwuArray[indexPath.row][@"everyoneAmount"]];
        cell.people.text = [NSString stringWithFormat:@"%@",_renwuArray[indexPath.row][@"counts"]];
    }
    return cell;
    
}




#pragma mark--键盘搜索事件
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSLog(@"点击了搜索");
    [self.view endEditing:YES];
    return YES;
}
//cell 分割线 两端封头 实现这个两个方法 1
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}



//任务列表
-(void)httpRquestRenWuUrl{
    
    __weak typeof(self) weakSelf = self;
    
    NSString *url = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"task/taskAllList.api?access_token="),NSUD_Obj(@"token")];
    [HTTPURL getRequest:url parameters:@{@"areaId":@"130100",@"pageIndex":@(page)} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        
        if ([responseObject[@"retFlag"]integerValue]==1) {
            NSDictionary *dic = [PublicTools dictionaryWithJsonString:responseObject[@"data"]];
            NSArray *array = [NSArray array];
            array = (NSArray *)dic[@"rows"];
            [_renwuArray addObjectsFromArray:array];
            [weakSelf.renwuTableView reloadData];
            [weakSelf.renwuTableView.mj_footer endRefreshing];
        }
        
    } filure:^(NSURLSessionDataTask *task, id error) {
        NSLog(@"%@",error);
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
